//!/bin/node
var url = require('url'),
    http = require('http');

http.createServer(function(req, res) {
    res.writeHead(200, {
        'Content-Type': 'application/json',
        'Access-Control-Allow-Credentials': 'true',
        'Access-Control-Allow-Origin': 'http://localhost:8080',
        'Access-Control-Allow-Methods': 'GET, POST, PUT, PATCH, DELETE, OPTIONS',
        'Set-Cookie': 'type=ninja'
    });
    if (req.method != 'OPTIONS' && req.method != 'HEAD') {

        // if (!req.headers.cookie) {
        //     res.setHeader("Set-Cookie", ["type=ninja", "language=javascript"]);
        // }

        res.write(JSON.stringify({
            code: 200,
            uri: 'http://' + req.headers.host + req.url,
            verb: req.method,
            message: 'hello world'
        }));
    }
    res.end();
}).listen(5052);

console.log('starting server on 5052');